import java.util.Scanner;

// 牛客

class TreeNode{
    public char val;
    public TreeNode left;
    public TreeNode right;

    public TreeNode(char val){
        this.val = val;
    }
}
    public class Main {

        public static int i = 0;
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            // 注意 hasNext 和 hasNextLine 的区别
            while (in.hasNextLine()) { // 注意 while 处理多个 case
                String str = in.nextLine();

                TreeNode root = createTree(str);

                inorder(root);
            }
        }

        public static TreeNode createTree(String str) {
            //1. 遍历字符串str
            // for(int i = 0;i < str.length();i++) {
            //     char ch = str.charAt(i);
            // }
            TreeNode root = null;
            if(str.charAt(i) != '#') {
                //2. 根据前序遍历创建二叉树
                root = new TreeNode(str.charAt(i));
                i++;
                root.left = createTree(str);
                root.right = createTree(str);
            }else {
                i++;
            }
            //3.返回根节点
            return root;
        }

        public static void inorder(TreeNode root) {
            if(root == null) {
                return ;
            }
            inorder(root.left);

            System.out.print(root.val+" ");

            inorder(root.right);

        }

        public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
            // 如果当前节点为空或等于p或q，返回当前节点
            if (root == null || root == p || root == q) {
                return root;
            }

            // 递归查找左子树和右子树
            TreeNode left = lowestCommonAncestor(root.left, p, q);
            TreeNode right = lowestCommonAncestor(root.right, p, q);

            // 如果p和q分别位于左右子树，则当前节点为最近公共祖先
            if (left != null && right != null) {
                return root;
            }

            // 如果p和q都在左子树，则返回左子树的结果；否则返回右子树的结果
            return left != null ? left : right;
        }


    }